package cn.crex1.xiaomi.dao.impl;

import cn.crex1.xiaomi.core.orm.template.QueryTemplate;
import cn.crex1.xiaomi.core.orm.template.util.QueryUtils;
import cn.crex1.xiaomi.dao.UserDao;
import cn.crex1.xiaomi.vo.UserVO;

public class UserDaoImpl implements UserDao{
	
	@Override
	public int selectOsUserByTelephoneAndPassword(UserVO uservo) {
		QueryTemplate queryTemplate =QueryUtils.openTemplate();
		UserDao userDao=queryTemplate.getmapper(UserDao.class, new Object[] {uservo.getTelephone(),uservo.getPassword()});
		/**
		 * 调用自身方法
		 * 注意点 如果返回list 就需要传递一个对象 这个对象跟操作的表对应的实体类对象
		 */
		return userDao.selectOsUserByTelephoneAndPassword(uservo);
	}

	@Override
	public int updateOsUserByTelephoneAndPassword(UserVO uservo) {
		QueryTemplate queryTemplate =QueryUtils.openTemplate();//调用封装模板
		
		UserDao userDao=queryTemplate.getmapper(UserDao.class, new Object[] {uservo.getUsername(),uservo.getPassword(),uservo.getTelephone(),uservo.getUpDate()});
		return userDao.updateOsUserByTelephoneAndPassword(uservo);
	}

	@Override
	public int selectOsUserByUserName(UserVO uservo) {
		QueryTemplate queryTemplate =QueryUtils.openTemplate();//调用封装模板
		UserDao userDao=queryTemplate.getmapper(UserDao.class, new Object[] {uservo.getUsername()});
		
		return userDao.selectOsUserByUserName(uservo);
	}

	@Override
	public int selectOsUserByTelephone(UserVO uservo) {
		QueryTemplate queryTemplate =QueryUtils.openTemplate();//调用封装模板
		UserDao userDao=queryTemplate.getmapper(UserDao.class, new Object[] {uservo.getTelephone()});
		
		return userDao.selectOsUserByTelephone(uservo);
	}

	@Override
	public String selectUsernameByUserId(Integer userId) {
		QueryTemplate queryTemplate=QueryUtils.openTemplate();
		UserDao userDao=queryTemplate.getmapper(UserDao.class, new Object[] {userId});
		return userDao.selectUsernameByUserId(userId);
	}

	@Override
	public Long selectTelephoneByUserId(Integer userId) {
		QueryTemplate queryTemplate=QueryUtils.openTemplate();
		UserDao userDao=queryTemplate.getmapper(UserDao.class, new Object[] {userId});
		return userDao.selectTelephoneByUserId(userId);
	}

	
}
